from pydantic import BaseModel, Field, root_validator


class _LanguageModel(BaseModel):
    name: str = Field(..., description="语言名字", max_length=8)
    code: str = Field(..., description="语言代码", max_length=8)

class AddNewLanguageModel(_LanguageModel):
    ...


class UpdateLanguageRequestModel(_LanguageModel):
    name: str = Field(None, description="语言名字", max_length=8)
    code: str = Field(None, description="语言代码", max_length=8)

    @root_validator()
    def validate_root(cls, attrs):
        if not any(attrs):
            raise ValueError("缺失更新参数")
        return attrs

